<?php


namespace app\system\service;

class LogService
{
	public static function getlist($options)
	{
		$where = [];
		if (!empty($options["admin_name"])) {
			$where[] = ["log.name", "like", "%" . $options["admin_name"] . "%"];
		}
		if (!empty($options["admin_id"])) {
			$where[] = ["log.admin_id", "=", $options["admin_id"]];
		}
		if (!empty($options["menu_id"])) {
			$where[] = ["menu.id", "=", $options["menu_id"]];
		}
		$count = \think\Db::name("system_admin_log")->alias("log")->join("system_admin_menu menu", "log.uri=menu.uri")->group("log.id")->where($where)->count();
		$pages = ceil($count / $options["limit"]);
		$list = \think\Db::name("system_admin_log")->alias("log")->join("system_admin_menu menu", "log.uri=menu.uri")->group("log.id")->field("log.*,menu.name as menu_name")->where($where)->page($options["page"], $options["limit"])->order("log.id", "desc")->select();
		$data = [];
		foreach ($list as $item) {
			$data[] = $item;
		}
		return ["code" => \app\system\model\Code::success, "data" => $data, "count" => $count, "pages" => $pages];
	}
}